<?php
if (!defined('ROOT')) exit('Can\'t Access !');

use library\core\db_conn;
use library\core\config;

abstract class module_class extends db_conn
{
    public function __construct($module, $action)
    {
        parent::__construct();

        $this->module = $module;
        $this->action = $action;

        $module_class = "{$module}_class";
        include_file("library/{$module_class}.php");
        if (class_exists($module_class)) {
            $this->mod = new $module_class($this);
        }
    }

    public function template($temp='', $pre='')
    {
        $module = $this->module;
        $action = $this->action;

        $template_dir = $module=='admin' ? 'admin' : config::get("template_dir");

        $this->tpldir = config::get('sitepath').'template/';
        $this->hempdir = config::get('sitepath')."template/{$template_dir}/";
        $template_dir = "{$template_dir}/{$module}";
        $this->tempdir = config::get('sitepath')."template/{$template_dir}/";

        if($temp){
            $this->tempdir .= "$temp/$pre/";
            $template_dir .= "/$temp/$pre";
        }

        include template($module.'_'.$action,$template_dir,'cache',"$temp/$pre");
        exit();
    }

    /**
     * 数据请求类实例
     *
     * @return \Input|null
     */
    final public function input()
    {
        include_file('include/Input.php');

        return \Input::getInstance();
    }
}
?>